package com.jiyi.widget.picselect;


import java.util.Collections;
import java.util.List;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.GridView;

import com.swift.base.ActivityBase;
import com.swift.maintenance.R;
import com.swift.utils.ActivityUtil;


public class Addpic_Activity extends ActivityBase implements OnClickListener
{

    private AlbumHelper picHelper;
    private List<ImageItem> images;
    private ImageGridAdapter adapter;
    private int max ;
    
    @SuppressWarnings("unchecked")
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addpic);
        ActivityUtil.getInstances().addPicSelect(this);
        picHelper = AlbumHelper.getHelper();
        picHelper.init(getApplicationContext());
        max =getIntent().getIntExtra("max", 6);
        images = (List<ImageItem>) getIntent().getSerializableExtra(
                "images");
        Collections.sort(images);
        initUI();
    }
    
    private void initUI()
    {
    	Log.e("current.size()", "="+PicSelectConstans.current.size());
    	findViewById(R.id.tv_choice).setOnClickListener(this);
    	findViewById(R.id.iv_back).setOnClickListener(this);
        GridView gv_add = (GridView) findViewById(R.id.gv_add);
        adapter = new ImageGridAdapter(Addpic_Activity.this, images,max);
        gv_add.setAdapter(adapter);
    }

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_choice:
			switch (PicSelectConstans.pic_tag) {
			case 1:
				ActivityUtil.getInstances().exitPicSelect();
				break;
			case 2 :
			case 3 :
			case 4 :
				PicSelectConstans.publish_pics.clear();
				PicSelectConstans.publish_pics.addAll(PicSelectConstans.current);
				PicSelectConstans.current.clear();
				ActivityUtil.getInstances().exitPicSelect();
				break ;
			}
			break;
		case R.id.iv_back:
			PicSelectConstans.headUrl = "";
	        finish();
			break ;
		default:
			break;
		}
		
	}
}
